package cn.wqk.rrtf.controller;

import cn.wqk.rrtf.mapper.TeacherMapper;
import cn.wqk.rrtf.mapper.UserMapper;
import cn.wqk.rrtf.pojo.*;
import cn.wqk.rrtf.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 吴青珂
 * @Date: 2020/07/16/18:45
 * @Description:
 */
@RequestMapping("/manager")
@Controller
public class ManagerController {
    @Autowired
    private UserService userService;
    @Autowired
    TeacherMapper teacherMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ChatService chatService;
    @Autowired
    private TeacherService teacherService;
    @RequestMapping("/test")
    @ResponseBody
    public String test(){
        return "ok";
    }
    @RequestMapping("/userList")
    public String userList(Model model){
        List<User> userList = userMapper.selectAllUser();
        model.addAttribute("userList",userList);
        return "manager/userList";
    }
    @RequestMapping("/articleList")
    public String articleList(Model model){
        List<Article> articleList = articleService.searchAllArticle();
        model.addAttribute("articleList",articleList);
        return "manager/articleList";
    }
    @RequestMapping("/courseList")
    public String courseList(Model model){
        List<Course> courseList = courseService.selectAllCourse();
        model.addAttribute("courseList",courseList);
        return "manager/courseList";
    }
    @RequestMapping("/chatList")
    public String chatList(Model model){
        List<Chat> chatList = chatService.selectAllChat();
        model.addAttribute("chatList",chatList);
        return "manager/chatList";
    }
    @RequestMapping("/teacherList")
    public String teacherList(Model model){
        List<Teacher> teacherList = teacherService.searchAllTeacher();
        List<Teacher> teacherList1 = teacherMapper.selectAllTeacher();
        System.out.println("t1="+teacherList1);
        System.out.println(teacherList);
        model.addAttribute("teacherList",teacherList);
        return "manager/teacherList";
    }
    @RequestMapping("/castleList")
    public String castleList(){
        return "manager/castleList";
    }
    @RequestMapping("/webList")
    public String webList(){
        return "manager/webList";
    }
    @RequestMapping("/deleteUser")
    @ResponseBody
    public String deleteUser(@RequestParam("userId")Integer userId){
        System.out.println("userId="+userId);
        return "ok";
    }
    @RequestMapping("/updateUser")
    @ResponseBody
    public String updateUser(@RequestParam("userId")Integer userId,
                             @RequestParam("username")String username,
                             @RequestParam("password")String password,
                             @RequestParam("email")String email,
                             @RequestParam("phone")String phone){
        User user = new User();
        user.setUserId(userId);
        user.setUsername(username);
        user.setPassword(password);
        user.setEmail(email);
        user.setPhone(phone);
        System.out.println(user);
        userService.updateUser(user);
        return "ok";
    }
}
